package main

import (
	"fmt"
	"math"
)

func minSubArrayLen(nums []int, target int) int {
	i, j := 0, 0
	minLen := math.MaxInt
	sum := 0
	for ; j < len(nums); j++ {
		sum += nums[j]
		for sum >= target {
			minLen = min(minLen, j-i+1)
			sum -= nums[i]
			i++
		}
	}

	if minLen == math.MaxInt {
		return 0
	}
	return minLen
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	fmt.Println(minSubArrayLen([]int{2, 3, 1, 2, 4, 3}, 7))
}
